function cleanup {
	echo cleaning up
	rm connection 2>/dev/null
	for pid in $created; do
		kill $pid
	done
	rm dispatcher.pid
}

echo $$>dispatcher.pid
echo creating the connection pipe
mkfifo connection
if [ $? -ne 0 ]; then
	exit 1
else
	trap "cont=; cleanup" SIGINT SIGSTOP
	cont=1
	while [ "$cont" ]; do
		nw=`mktemp -d`
		mkfifo "$nw/send"
		mkfifo "$nw/recv"
		echo $nw>connection
		./thread.sh "$nw" "$nw/send" "$nw/recv" &
		created=$created $!
	done
	cleanup
fi
